# Maintainer: Rémi BERTHO <remi.bertho@openmailbox.org>

_realname=libharu
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.3.0
pkgrel=2
pkgdesc="C library for generating PDF documents (mingw-w64)"
url="https://github.com/libharu/libharu"
arch=('any')
license=('custom:ZLIB')
depends=("${MINGW_PACKAGE_PREFIX}-libpng")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake")
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/libharu/libharu/archive/RELEASE_${pkgver//./_}.tar.gz"
        "win_various_install_files.patch"
        "win_lib.patch")
sha256sums=('8f9e68cc5d5f7d53d1bc61a1ed876add1faf4f91070dbc360d8b259f46d9a4d2'
            '2f5b85a98d650909e221d8dd57ed6f0eff7eca2695ddfd5fbd8727a798c5e9bf'
            'ff416a8a2f991652169c330b3a374e66fbe85f62a7b41a3519e4a9b22a51fe02')

prepare() {
  cd "${srcdir}/${_realname}-RELEASE_${pkgver//./_}"
  patch -p1 -i "${srcdir}/win_various_install_files.patch"
  patch -p1 -i "${srcdir}/win_lib.patch"
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_SHARED_LIBS=ON \
    -DBUILD_STATIC_LIBS=ON \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ../${_realname}-RELEASE_${pkgver//./_}

  make
}

package() {
  cd build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install
}
